package com.example.lenjor.sprite.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.lenjor.sprite.R;
import com.example.lenjor.sprite.bean.ChongZhiInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/7/2 0002.
 */
public class ChongZhiAdapter extends BaseAdapter{
    private Context context;
    private List<ChongZhiInfo> data;        //数据源
    private ChongZhiInfo bean;
    private TextView tv_youhui;
    private ImageView iv_image;
    private Button btn_price;
    private TextView tv_content;
    public ChongZhiAdapter(Context context,List<ChongZhiInfo> data){
        this.context = context;
        if(data != null){
            this.data = data;
        }else {
            this.data = new ArrayList<>();
        }

    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            convertView = View.inflate(context, R.layout.item_view_chongzhi_lv,null);
        }
        //取出数据
        bean = data.get(position);
        //获取单元格布局中的控件
        tv_youhui = (TextView) convertView.findViewById(R.id.tv_youhui);
        iv_image = (ImageView) convertView.findViewById(R.id.iv_item);
        btn_price = (Button)convertView.findViewById(R.id.btn_price);
        tv_content = (TextView)convertView.findViewById(R.id.tv_content);

        tv_youhui.setText(bean.getYouhui());
        iv_image.setImageResource(bean.getImage());
        btn_price.setText(bean.getPriceStr());
        tv_content.setText(bean.getContent());
        return convertView;
    }
}
